//
//  MainViewController.m
//  
//
//  Created by Apple on 2016/12/31.
//
//
#import "SDCycleScrollView.h"
#import "MainViewController.h"
#import "MainTableViewCell.h"
@interface MainViewController ()

@property(nonatomic,strong)UISearchBar *searchBar;
@property(nonatomic,strong)SDCycleScrollView *cycleScrollView;

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor redColor];
   
    [self setLeftTextBarButtonItemWithFrame:CGRectMake(10, 32, 40, 32) title:@"太原" titleColor:[UIColor blackColor] backImage:nil selectBackImage:nil action:nil];
   
    [self customserchbr];
    [self customLunBo];
    [self customTableView];
    self.tableview.frame=CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT-64);
    UINib *footerNib= [UINib nibWithNibName:@"MainTableViewCell" bundle:nil];
    [self.tableview registerNib:footerNib forCellReuseIdentifier:@"MainTableViewCell"];
    self.dataArray = @[@"1",@"1",@"2",@"3"];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 200;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 370;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{

    NSArray *imageNames = @[@"h1.jpg",
                            @"h2.jpg",
                            @"h3.jpg",
                            @"h4.jpg",
                            // 本地图片请填写全名
                            ];
    
    _cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0,0, SCREEN_WIDTH,150) shouldInfiniteLoop:YES imageNamesGroup:imageNames];
    _cycleScrollView.delegate = self;
    _cycleScrollView.scrollDirection = UICollectionViewScrollDirectionVertical;
    _cycleScrollView.backgroundColor = [UIColor blackColor];
    _cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated;
    _cycleScrollView.scrollDirection =UICollectionViewScrollDirectionHorizontal
    ;
    //--- 轮播时间间隔，默认1.0秒，
    _cycleScrollView.autoScrollTimeInterval = 1.5;
        UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 200)];
        view1.backgroundColor = [UIColor whiteColor];
        [view1 addSubview:_cycleScrollView];
    
    return view1;
    
   }

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MainTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MainTableViewCell" forIndexPath:indexPath];
    
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSLog(@"基类里输出请重写方法");
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (self.didSelectCellBlock) {
        self.didSelectCellBlock(indexPath) ;
        
    }
}

-(void)customLunBo{
    
}
-(void)customserchbr{
    _searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(60, 0, 260, 28)];
    _searchBar.barStyle = UIBarStyleBlack;
    _searchBar.backgroundImage = [UIImage imageNamed:@"btu_search"];
    _searchBar.placeholder = @"搜索";
     _searchBar.searchBarStyle = UISearchBarStyleProminent;
    _searchBar.delegate = self;
    UIBarButtonItem *searchButton = [[UIBarButtonItem alloc]initWithCustomView:_searchBar];
    self.navigationItem.titleView = _searchBar;
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[_searchBar resignFirstResponder];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
